package com.noshufou.android.su.widget;

import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.GradientDrawable.Orientation;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RectShape;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.widget.TextView;
import com.noshufou.android.su.R.styleable;

public class PagerHeader extends ViewGroup
{
  private static final int LEFT_ZONE = -1;
  private static final int MIDDLE_ZONE = 0;
  private static final int RIGHT_ZONE = 1;
  private static final String TAG = "Su.PagerHeader";
  private static DisplayMetrics mDisplayMetrics;
  private ColorSet mActiveTextColor;
  private boolean mAlwaysInTapRegion;
  private ShapeDrawable mBottomBar;
  private int mBottomBarHeight;
  private boolean mChangeOnClick = true;
  private Context mContext;
  private MotionEvent mCurrentDownEvent;
  private int mDisplayedPage = 0;
  private GradientDrawable mFadingEdgeLeft;
  private int mFadingEdgeLength;
  private GradientDrawable mFadingEdgeRight;
  private ColorSet mInactiveTextColor;
  private int mLeftZoneEdge;
  private OnHeaderClickListener mOnHeaderClickListener = null;
  private int mPaddingPush;
  private int mRightZoneEdge;
  private GradientDrawable mShadow;
  private int mShadowHeight;
  private boolean mShowBottomBar;
  private boolean mShowTab;
  private boolean mShowTopShadow;
  private ColorSet mTabColor;
  private ShapeDrawable mTabDrawable;
  private int mTabHeight;
  private int mTabPadding;
  private int mTouchSlopSquare;
  private boolean mTouchZonesAccurate;

  public PagerHeader(Context paramContext, AttributeSet paramAttributeSet)
  {
    super(paramContext, paramAttributeSet);
    this.mContext = paramContext;
    mDisplayMetrics = paramContext.getResources().getDisplayMetrics();
    TypedArray localTypedArray = paramContext.obtainStyledAttributes(paramAttributeSet, R.styleable.PagerHeader, 0, 0);
    this.mActiveTextColor = new ColorSet(localTypedArray.getColor(0, -16777216));
    this.mInactiveTextColor = new ColorSet(localTypedArray.getColor(1, -12303292));
    this.mTabColor = new ColorSet(localTypedArray.getColor(2, this.mActiveTextColor.getColor()));
    this.mTabHeight = localTypedArray.getDimensionPixelSize(3, dipToPixels(4.0F));
    this.mTabPadding = localTypedArray.getDimensionPixelSize(4, dipToPixels(10.0F));
    this.mPaddingPush = localTypedArray.getDimensionPixelSize(5, dipToPixels(50.0F));
    this.mFadingEdgeLength = localTypedArray.getDimensionPixelSize(6, dipToPixels(30.0F));
    this.mShowTopShadow = localTypedArray.getBoolean(9, true);
    this.mShowBottomBar = localTypedArray.getBoolean(10, true);
    this.mShowTab = localTypedArray.getBoolean(11, true);
    ColorSet localColorSet = new ColorSet(0);
    if (localTypedArray.hasValue(8))
    {
      int j = localTypedArray.getColor(8, 0);
      setBackgroundColor(j);
      localColorSet.setColor(j);
    }
    while (true)
    {
      this.mTabDrawable = new ShapeDrawable(new RectShape());
      this.mTabDrawable.getPaint().setColor(this.mTabColor.getColor());
      this.mBottomBar = new ShapeDrawable(new RectShape());
      this.mBottomBar.getPaint().setColor(this.mTabColor.getColor());
      this.mBottomBarHeight = dipToPixels(2.0F);
      GradientDrawable.Orientation localOrientation = GradientDrawable.Orientation.TOP_BOTTOM;
      int[] arrayOfInt1 = new int[2];
      arrayOfInt1[0] = -2013265920;
      this.mShadow = new GradientDrawable(localOrientation, arrayOfInt1);
      this.mShadowHeight = dipToPixels(3.0F);
      int[] arrayOfInt2 = new int[2];
      arrayOfInt2[0] = localColorSet.getColor();
      arrayOfInt2[1] = localColorSet.getColor(0);
      this.mFadingEdgeLeft = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, arrayOfInt2);
      this.mFadingEdgeRight = new GradientDrawable(GradientDrawable.Orientation.RIGHT_LEFT, arrayOfInt2);
      int i = ViewConfiguration.get(paramContext).getScaledTouchSlop();
      this.mTouchSlopSquare = (i * i);
      return;
      if (localTypedArray.hasValue(7))
      {
        localColorSet.setColor(localTypedArray.getColor(7, 0));
        continue;
      }
      Log.w("Su.PagerHeader", "Either backgroundColor or fadingEdgeColorHint must be specified to enable fading edges");
      localColorSet.setColor(0);
    }
  }

  private static int dipToPixels(float paramFloat)
  {
    return (int)(0.5F + paramFloat * mDisplayMetrics.density);
  }

  private int getTouchZone(MotionEvent paramMotionEvent)
  {
    int i = 0;
    if (this.mTouchZonesAccurate)
    {
      int i3 = (int)paramMotionEvent.getX();
      if ((i3 < this.mLeftZoneEdge) && (this.mDisplayedPage > 0));
      for (i = -1; ; i = 1)
        do
          return i;
        while (((i3 > this.mLeftZoneEdge) && (i3 < this.mRightZoneEdge)) || (i3 <= this.mRightZoneEdge) || (this.mDisplayedPage >= -1 + getChildCount()));
    }
    View localView1 = getChildAt(this.mDisplayedPage);
    int j = localView1.getLeft();
    int k = localView1.getRight();
    View localView2 = getChildAt(-1 + this.mDisplayedPage);
    int m;
    label129: int n;
    label153: int i1;
    if (localView2 != null)
    {
      m = localView2.getRight();
      View localView3 = getChildAt(1 + this.mDisplayedPage);
      if (localView3 == null)
        break label205;
      n = localView3.getLeft();
      if (m >= 0)
        break label212;
      i1 = 0;
      label161: this.mLeftZoneEdge = i1;
      if (n >= 0)
        break label227;
    }
    label205: label212: label227: for (int i2 = getWidth(); ; i2 = n - (n - k) / 2)
    {
      this.mRightZoneEdge = i2;
      this.mTouchZonesAccurate = true;
      i = getTouchZone(paramMotionEvent);
      break;
      m = -1;
      break label129;
      n = -1;
      break label153;
      i1 = m + (j - m) / 2;
      break label161;
    }
  }

  private static int map(float paramFloat1, float paramFloat2, float paramFloat3, int paramInt1, int paramInt2)
  {
    return (int)((paramFloat1 - paramFloat2) * (paramInt2 - paramInt1) / (paramFloat3 - paramFloat2) + paramInt1);
  }

  private void onTap(MotionEvent paramMotionEvent)
  {
    int i = getTouchZone(paramMotionEvent);
    if (this.mOnHeaderClickListener != null)
      this.mOnHeaderClickListener.onHeaderClicked(i + this.mDisplayedPage);
    if ((this.mChangeOnClick) && (i != 0))
    {
      setDisplayedPage(i + this.mDisplayedPage);
      if (this.mOnHeaderClickListener != null)
        this.mOnHeaderClickListener.onHeaderSelected(this.mDisplayedPage);
    }
  }

  private void showPress(MotionEvent paramMotionEvent, boolean paramBoolean)
  {
    TextView localTextView;
    if (getTouchZone(paramMotionEvent) != 0)
    {
      localTextView = (TextView)getChildAt(this.mDisplayedPage + getTouchZone(paramMotionEvent));
      if (!paramBoolean)
        break label46;
    }
    label46: for (int i = this.mActiveTextColor.getColor(); ; i = this.mInactiveTextColor.getColor())
    {
      localTextView.setTextColor(i);
      return;
    }
  }

  public void add(int paramInt, String paramString)
  {
    TextView localTextView = new TextView(this.mContext);
    localTextView.setTextColor(this.mInactiveTextColor.getColor());
    localTextView.setTextSize(16.0F);
    localTextView.setText(paramString);
    addView(localTextView);
  }

  protected void dispatchDraw(Canvas paramCanvas)
  {
    super.dispatchDraw(paramCanvas);
    this.mFadingEdgeLeft.draw(paramCanvas);
    this.mFadingEdgeRight.draw(paramCanvas);
    if (this.mShowTopShadow)
      this.mShadow.draw(paramCanvas);
    if (this.mShowBottomBar)
      this.mBottomBar.draw(paramCanvas);
    if (this.mShowTab)
      this.mTabDrawable.draw(paramCanvas);
  }

  public boolean getChangeOnClick()
  {
    return this.mChangeOnClick;
  }

  protected void onLayout(boolean paramBoolean, int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    int i = paramInt3 - paramInt1;
    int j = paramInt4 - paramInt2;
    for (int k = 0; ; k++)
    {
      if (k >= getChildCount())
      {
        setPosition(this.mDisplayedPage, 0.0F, 0);
        this.mShadow.setBounds(0, 0, i, this.mShadowHeight);
        this.mBottomBar.setBounds(0, j - this.mBottomBarHeight, i, j);
        this.mFadingEdgeLeft.setBounds(0, this.mShadowHeight, this.mFadingEdgeLength, j - this.mBottomBarHeight);
        this.mFadingEdgeRight.setBounds(i - this.mFadingEdgeLength, this.mShadowHeight, i, j - this.mBottomBarHeight);
        return;
      }
      TextView localTextView = (TextView)getChildAt(k);
      int m = localTextView.getMeasuredWidth();
      int n = localTextView.getMeasuredHeight();
      int i1 = j / 2 - (n - localTextView.getLineHeight() * localTextView.getLineCount() / 2);
      localTextView.layout(i, i1, i + m, i1 + n);
    }
  }

  protected void onMeasure(int paramInt1, int paramInt2)
  {
    int i = 0;
    int j = 0;
    for (int k = 0; ; k++)
    {
      if (k >= getChildCount())
      {
        setMeasuredDimension(resolveSize(j + 2 * this.mFadingEdgeLength, paramInt1), resolveSize(i + getPaddingTop() + getPaddingBottom() + this.mShadowHeight + this.mTabHeight, paramInt2));
        return;
      }
      View localView = getChildAt(k);
      localView.measure(0, 0);
      i = Math.max(i, localView.getMeasuredHeight());
      j = Math.max(j, localView.getMeasuredWidth());
    }
  }

  public boolean onTouchEvent(MotionEvent paramMotionEvent)
  {
    int i = paramMotionEvent.getAction();
    float f1 = paramMotionEvent.getX();
    float f2 = paramMotionEvent.getY();
    switch (i)
    {
    default:
    case 0:
    case 2:
    case 1:
    }
    while (true)
    {
      return true;
      if (this.mCurrentDownEvent != null)
        this.mCurrentDownEvent.recycle();
      this.mCurrentDownEvent = MotionEvent.obtain(paramMotionEvent);
      this.mAlwaysInTapRegion = true;
      showPress(this.mCurrentDownEvent, true);
      continue;
      if (!this.mAlwaysInTapRegion)
        continue;
      int j = (int)(f1 - this.mCurrentDownEvent.getX());
      int k = (int)(f2 - this.mCurrentDownEvent.getY());
      if (j * j + k * k <= this.mTouchSlopSquare)
        continue;
      this.mAlwaysInTapRegion = false;
      showPress(this.mCurrentDownEvent, false);
      continue;
      showPress(this.mCurrentDownEvent, false);
      if (!this.mAlwaysInTapRegion)
        continue;
      onTap(this.mCurrentDownEvent);
    }
  }

  public void setChangeOnClick(boolean paramBoolean)
  {
    this.mChangeOnClick = paramBoolean;
  }

  public void setDisplayedPage(int paramInt)
  {
    this.mDisplayedPage = paramInt;
  }

  public void setOnHeaderClickListener(OnHeaderClickListener paramOnHeaderClickListener)
  {
    this.mOnHeaderClickListener = paramOnHeaderClickListener;
  }

  public void setPosition(int paramInt1, float paramFloat, int paramInt2)
  {
    this.mTouchZonesAccurate = false;
    int i = getWidth();
    int j = i / 2;
    if (paramInt1 >= 0)
    {
      int i15 = getChildCount();
      if (paramInt1 < i15)
      {
        TextView localTextView4 = (TextView)getChildAt(paramInt1);
        int i16 = localTextView4.getWidth();
        int i17 = 0;
        if (paramInt1 + 1 < getChildCount())
          i17 = Math.min(0, j - getChildAt(paramInt1 + 1).getWidth() / 2 - this.mPaddingPush - i16);
        int i18 = map(paramFloat, 1.0F, 0.0F, i17, j - i16 / 2);
        localTextView4.layout(i18, localTextView4.getTop(), i18 + i16, localTextView4.getBottom());
        localTextView4.setTextColor(Color.rgb(map(paramFloat, 1.0F, 0.0F, this.mInactiveTextColor.red, this.mActiveTextColor.red), map(paramFloat, 1.0F, 0.0F, this.mInactiveTextColor.green, this.mActiveTextColor.green), map(paramFloat, 1.0F, 0.0F, this.mInactiveTextColor.blue, this.mActiveTextColor.blue)));
      }
    }
    if (paramInt1 + 1 < getChildCount())
    {
      TextView localTextView3 = (TextView)getChildAt(paramInt1 + 1);
      int i12 = localTextView3.getWidth();
      int i13 = getChildAt(paramInt1).getWidth();
      int i14 = map(paramFloat, 1.0F, 0.0F, j - i12 / 2, Math.max(i - i12, j + i13 / 2 + this.mPaddingPush));
      localTextView3.layout(i14, localTextView3.getTop(), i14 + i12, localTextView3.getBottom());
      localTextView3.setTextColor(Color.rgb(map(paramFloat, 1.0F, 0.0F, this.mActiveTextColor.red, this.mInactiveTextColor.red), map(paramFloat, 1.0F, 0.0F, this.mActiveTextColor.green, this.mInactiveTextColor.green), map(paramFloat, 1.0F, 0.0F, this.mActiveTextColor.blue, this.mInactiveTextColor.blue)));
    }
    if (paramInt1 > 0)
    {
      TextView localTextView2 = (TextView)getChildAt(paramInt1 - 1);
      int i7 = getChildAt(paramInt1).getLeft();
      int i8 = localTextView2.getLeft();
      int i9 = localTextView2.getWidth();
      if ((i7 < i8 + i9 + this.mPaddingPush) || (i8 < 0))
      {
        int i10 = Math.min(0, i7 - i9 - this.mPaddingPush);
        localTextView2.layout(i10, localTextView2.getTop(), i10 + i9, localTextView2.getBottom());
        int i11 = map(paramFloat, 1.0F, 0.0F, 0, 255);
        localTextView2.setTextColor(this.mInactiveTextColor.getColor(i11));
      }
    }
    if (paramInt1 + 2 < getChildCount())
    {
      TextView localTextView1 = (TextView)getChildAt(paramInt1 + 2);
      int i2 = getChildAt(paramInt1 + 1).getRight();
      int i3 = localTextView1.getLeft();
      int i4 = localTextView1.getWidth();
      if ((i2 > i3 - this.mPaddingPush) || (i3 + i4 > i))
      {
        int i5 = Math.max(i2 + this.mPaddingPush, i - i4);
        localTextView1.layout(i5, localTextView1.getTop(), i5 + i4, localTextView1.getBottom());
        int i6 = map(paramFloat, 0.0F, 1.0F, 0, 255);
        localTextView1.setTextColor(this.mInactiveTextColor.getColor(i6));
      }
    }
    if (paramFloat < 0.5F);
    while (true)
    {
      View localView = getChildAt(paramInt1);
      int k = localView.getLeft();
      int m = localView.getRight();
      float f = Math.abs(paramFloat - 0.5F) / 0.5F;
      int n = (int)(f * this.mTabHeight);
      int i1 = (int)(255.0F * f);
      this.mTabDrawable.setBounds(k - this.mTabPadding, getHeight() - n, m + this.mTabPadding, getHeight());
      this.mTabDrawable.setAlpha(i1);
      return;
      paramInt1++;
    }
  }

  private class ColorSet
  {
    public int alpha;
    public int blue;
    public int green;
    public int red;

    ColorSet(int arg2)
    {
      int i;
      setColor(i);
    }

    public int getColor()
    {
      return Color.argb(this.alpha, this.red, this.green, this.blue);
    }

    public int getColor(int paramInt)
    {
      return Color.argb(paramInt, this.red, this.green, this.blue);
    }

    public void setColor(int paramInt)
    {
      this.alpha = Color.alpha(paramInt);
      this.red = Color.red(paramInt);
      this.green = Color.green(paramInt);
      this.blue = Color.blue(paramInt);
    }
  }

  public static abstract interface OnHeaderClickListener
  {
    public abstract void onHeaderClicked(int paramInt);

    public abstract void onHeaderSelected(int paramInt);
  }
}

/* Location:           D:\Development\Decompile_Workspace\슈퍼유저-41\classes_dex2jar.jar
 * Qualified Name:     com.noshufou.android.su.widget.PagerHeader
 * JD-Core Version:    0.6.0
 */